﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace EMoney.IStock.OAuth.Framework
{
    public class StringHelper
    {
        public static string GetTrendsFile(string file)
        {
            UrlHelper he = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
            string path = he.Content("~/" + file);
            return path;
        }

        /// <summary>
        /// 获取16位唯一字符串
        /// </summary>
        /// <returns></returns>
        public static string GetUniqueNo()
        {
            long i = 1;
            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }

        /// <summary>
        /// 获取32位唯一字符串
        /// </summary>
        /// <returns></returns>
        public static string GetRequestTID()
        {
            string tid = Guid.NewGuid().ToString("N");

            if (!string.IsNullOrEmpty(tid))
            {
                CacheManager.DefaultCache.Set<string>(tid, tid,10);
            }

            return tid;
        }
    }
}
